package com.company.common.config;

import com.github.xiaoymin.swaggerbootstrapui.annotations.EnableSwaggerBootstrapUI;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
@EnableSwaggerBootstrapUI
public class SwaggerConfig implements WebMvcConfigurer {

    @Bean
    public Docket getDocket() {

        //1.创建摘要对象
        Docket docket = new Docket(DocumentationType.SWAGGER_2);

        //2.创建ApiInfo的构建对象
        ApiInfoBuilder apiInfoBuilder = new ApiInfoBuilder();

        //创建联系对象
        Contact contact = new Contact("erp", "http://www.xiaolangwnag_erp.com", "1579321143@qq.com");
        //设置联系信息
        apiInfoBuilder.contact(contact);
        //设置文档标题，描述，版本
        apiInfoBuilder.title("ERP项目开发文档");
        apiInfoBuilder.description("描述：很有前途的项目");
        apiInfoBuilder.version("1.0.0");

        //使用ApiInfo构建对象
        ApiInfo apiInfo = apiInfoBuilder.build();

        docket = docket.apiInfo(apiInfo) //
                .select()//查询apiInfo的信息
                .paths(PathSelectors.any()) //
                .apis(RequestHandlerSelectors.basePackage("com.company"))//
                .build();

        return docket;
    }

}
